﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HML.Demo
{
    public partial class MultidropSlideForm : ItemFormTemplate
    {
        public MultidropSlideForm()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.Form_Load);
            this.Shown += new System.EventHandler(this.Form_Shown);
        }

        #region 实现

        public override ItemFormTemplateViewObject AsynchRequestTask(ItemFormTemplateViewObject view)
        {
            System.Threading.Thread.Sleep(300);
            view.ViewData = DemoHelper.GetDescription(AppDomain.CurrentDomain.BaseDirectory + "例子\\控件\\MultidropSlideForm\\MultidropSlideForm.rtf");
            return view;
        }

        public override void DataBind(ItemFormTemplateViewObject viewObject)
        {
            this.introduceBrowser.Rtf = viewObject.ViewData.ToString();
        }

        public override void ShowView()
        {
            base.ShowView();
        }

        public override void HideView()
        {
            base.HideView();
        }

        public override void CloseView()
        {
            base.CloseView();
        }

        #endregion

        #region 属性面板

        private void Form_Load(object sender, EventArgs e)
        {
            this.controlContainer.SizeChanged += this.ControlContainer_SizeChanged;

            this.demo_control.Orientation = MultidropSlideOrientation.HorizontalTop;
            this.demo_control.Track.RoundEnabled = true;
            this.demo_control.Track.Thickness = 8;
            this.demo_control.Thumb.Diameter = 18;
            this.demo_control.Thumb.InfluencedEnabled = false;
            this.demo_control.TipTitle.Visible = false;
            this.demo_control.TipValue.Visible = true;
            this.demo_control.OrientationMargin.TrackTitle = 28;

            this.orientation_dropDownListPlus.Multiple = false;
            this.orientation_dropDownListPlus.BindEnumList<MultidropSlideOrientation>(this.demo_control.Orientation);
            this.orientation_dropDownListPlus.SelectedItemsChanged += this.Orientation_dropDownListPlus_SelectedItemsChanged;

            this.poleRoundEnabled_toggleSwitch.IsOn = this.demo_control.Track.RoundEnabled;
            this.poleRoundEnabled_toggleSwitch.Toggled += this.Track_RoundEnabled_toggleSwitch_Toggled;

            this.poleThickness__label.Text = this.demo_control.Track.Thickness.ToString();
            this.poleThickness_trackBarPlus.Value = this.demo_control.Track.Thickness;
            this.poleThickness_trackBarPlus.ValueChanged += this.Track_Thickness_trackBarPlus_ValueChanged;

            this.lumpDiameter_label.Text = this.demo_control.Thumb.Diameter.ToString();
            this.lumpDiameter_trackBarPlus.Value = this.demo_control.Thumb.Diameter;
            this.lumpDiameter_trackBarPlus.ValueChanged += this.Thumb_Diameter_trackBarPlus_ValueChanged;

            this.lumpInfluencedEnabled_toggleSwitch.IsOn = this.demo_control.Thumb.InfluencedEnabled;
            this.lumpInfluencedEnabled_toggleSwitch.Toggled += Thumb_InfluencedEnabled_toggleSwitch_Toggled;

            this.tipTitleVisible_toggleSwitch.IsOn = this.demo_control.TipTitle.Visible;
            this.tipTitleVisible_toggleSwitch.Toggled += this.TipTitleVisible_toggleSwitch_Toggled;

            this.tipValueVisible_toggleSwitch.IsOn = this.demo_control.TipValue.Visible;
            this.tipValueVisible_toggleSwitch.Toggled += this.TipValueVisible_toggleSwitch_Toggled;

        }

        private void Form_Shown(object sender, EventArgs e)
        {
            this.splitContainer.SplitterDistance = Math.Max(this.splitContainer.Width / 4, this.splitContainer.Width - MainForm.GlobalSplitWidth);
            this.splitContainer.SplitterMoved += this.SplitContainer_SplitterMoved;

            MainForm.LoadAssistTabControl(this.assistTabControl);
        }

        private void SplitContainer_SplitterMoved(object sender, SplitterEventArgs e)
        {
            SplitContainer control = (SplitContainer)sender;
            MainForm.GlobalSplitWidth = this.splitContainer.Width - control.SplitterDistance;
        }

        private void ControlContainer_SizeChanged(object sender, EventArgs e)
        {
            Panel control = (Panel)sender;
            this.demo_control.Location = new Point((control.Width - this.demo_control.Width) / 2, (control.Height - this.demo_control.Height) / 2);
        }

        private void Orientation_dropDownListPlus_SelectedItemsChanged(object sender, EventArgs e)
        {
            DropDownListPlus control = (DropDownListPlus)sender;
            this.demo_control.Orientation = (MultidropSlideOrientation)control.SelectedItem.Tag;
        }

        private void Track_RoundEnabled_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.Track.RoundEnabled = control.IsOn; 
        }

        private void Track_Thickness_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.Track.Thickness = (int)control.Value;
            this.poleThickness__label.Text = this.demo_control.Track.Thickness.ToString(); 
        }

        private void Thumb_Diameter_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.Thumb.Diameter = (int)control.Value;
            this.lumpDiameter_label.Text = this.demo_control.Thumb.Diameter.ToString(); 
        }

        private void Thumb_InfluencedEnabled_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.Thumb.InfluencedEnabled = control.IsOn; 
        }

        private void TipTitleVisible_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.TipTitle.Visible = control.IsOn;
        }

        private void TipValueVisible_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.TipValue.Visible = control.IsOn;
        }

        #endregion

    }
}
